#include "renderer.h"

#include <iostream>

void GLClearError()
{
    while (glGetError() != GL_NO_ERROR);
}

bool GLLogCall(const char* call, const char* file, int32_t line)
{
    while (GLenum error = glGetError()) {
        std::cerr << "[OpenGL Error(" << error << ")] " <<
            file << ":" << line << " " << call << std::endl;
        return false;
    }
    return true;
}

void Renderer::Clear()
{
    GLCALL(glClear(GL_COLOR_BUFFER_BIT));
}

void Renderer::Draw(const VertexArray &va, const IndexBuffer &ib, const Shader& shader)
{
    shader.Bind();
    va.Bind();
    ib.Bind();
    GLCALL(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, nullptr));
}
